//
//  UIStandardRateControlButton.m
//  vhECGTools
//
//  Created by jia yu on 2022/7/17.
//

#import "UIStandardRateControlButton.h"
#import <vhECGTools/vhECGTools.h>
#import <ZMFoundation/ZMFoundation.h>
#import <ZMUIKit/ZMUIKit.h>
@interface UIStandardRateControlButton(){
    NSBundle *myBundle;
}
@end

@implementation UIStandardRateControlButton

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        NSBundle *frameBundle = [NSBundle ex_bundleWithName:@"vhECGTools"];
        myBundle = [[NSBundle alloc] initWithPath:[frameBundle pathForResource:@"UIStandardRateControlButton" ofType:@"bundle"]];
        
        CGSize buttonSize = frame.size;
        UIColor *titleColor = [vhECGTools colorFromHEXStringwithR:@"29" G:@"45" B:@"59"];
        
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:[myBundle pathForResource:@"button" ofType:@"png"]];
        image = [vhECGTools scaleImage:image to:buttonSize];
//        UIGraphicsBeginImageContextWithOptions(buttonSize, NO, 2.f);
//        [image drawInRect:CGRectMake(0.f, 0.f, buttonSize.width, buttonSize.height)];
//        image = UIGraphicsGetImageFromCurrentImageContext();
//        UIGraphicsEndImageContext();

        UIImage *image_hightlighted = [[UIImage alloc] initWithContentsOfFile:[myBundle pathForResource:@"button_highlighted" ofType:@"png"]];
        image_hightlighted = [vhECGTools scaleImage:image_hightlighted to:buttonSize];
//        UIGraphicsBeginImageContextWithOptions(buttonSize, NO, 2.f);
//        [image_hightlighted drawInRect:CGRectMake(0.f, 0.f, buttonSize.width, buttonSize.height)];
//        image_hightlighted = UIGraphicsGetImageFromCurrentImageContext();
//        UIGraphicsEndImageContext();

        self.backgroundColor = [UIColor clearColor];
        [self setTitleColor:titleColor forState:UIControlStateNormal];
        self.titleLabel.font = ZMSysFont(0.3f * frame.size.height, ZMFontWeightSemibold);
        self.layer.masksToBounds = NO;
        [self setBackgroundImage:image forState:UIControlStateNormal];
        [self setBackgroundImage:image_hightlighted forState:UIControlStateHighlighted];
    }
    return self;
}

@end
